package com.protocolterminal.DataField;

import java.util.List;

import com.protocolterminal.AFN.AFN00;
import com.protocolterminal.AFN.AFN01;
import com.protocolterminal.AFN.AFN04;
import com.protocolterminal.AFN.AFN09;
import com.protocolterminal.AFN.AFN0A;
import com.protocolterminal.AFN.AFN10;
import com.protocolterminal.AFN.BaseAFN;

public class GetDataField_STS implements GetDataField {

	/* (non-Javadoc)
	 * @see com.protocolterminal.DataField.ProtocolGetDataField1#Decode(java.lang.String, java.lang.String, java.util.List, java.util.List, java.util.List, java.lang.String)
	 */
	@Override
	public String Encode(String AFN, String SEQ, List<String> DA, List<String> DT, List<String> Data, String AUX) {
		if (DA.size() != DT.size() || DT.size() != Data.size()) {
			return null;
		}

		String datafield = "";

		// UNDO
		BaseAFN baseAFN = null;
		switch (AFN.toUpperCase()) {
		case "00":
			// 确认∕否认
			baseAFN = new AFN00(AFN, SEQ, DA, DT, Data, AUX);
			break;
		case "01":
			// 复位
			baseAFN = new AFN01(AFN, SEQ, DA, DT, Data, AUX);
			break;
		case "04":
			// 设置参数
			baseAFN = new AFN04(AFN, SEQ, DA, DT, Data, AUX);
			break;
		case "09":
			// 请求终端配置
			baseAFN = new AFN09(AFN, SEQ, DA, DT, Data, AUX);
			break;
		case "0A":
			// 查询参数
			baseAFN = new AFN0A(AFN, SEQ, DA, DT, Data, AUX);
			break;
		case "0B":
			// 请求任务数据
			break;
		case "0C":
			// 请求1类数据（实时数据）
			break;
		case "0D":
			// 请求2类数据（历史数据）
			break;
		case "0E":
			// 请求3类数据（事件数据
			break;
		case "10":
			// 数据转发
			baseAFN = new AFN10(AFN, SEQ, DA, DT, Data, AUX);
			break;
		default:
			break;
		}

		datafield += baseAFN.toString();

		return datafield;
	}

	/* (non-Javadoc)
	 * @see com.protocolterminal.DataField.ProtocolGetDataField1#Encode(java.lang.String)
	 */
	@Override
	public BaseAFN Decode(String datafield) {
		BaseAFN baseAFN = null;

		switch (datafield.substring(0, 2).toUpperCase()) {
		case "00":
			// 确认∕否认
			baseAFN = new AFN00(datafield);
			break;
		case "09":
			// 请求终端配置
			baseAFN = new AFN09(datafield);
			break;
		case "0A":
			// 查询参数
			baseAFN = new AFN0A(datafield);
			break;
		case "0B":
			// 请求任务数据
			break;
		case "0C":
			// 请求1类数据（实时数据）
			break;
		case "0D":
			// 请求2类数据（历史数据）
			break;
		case "0E":
			// 请求3类数据（事件数据
			break;
		case "10":
			// 数据转发
			baseAFN = new AFN10(datafield);
			break;
		default:
			break;
		}

		return baseAFN;
	}

}
